home *** CD-ROM | disk | FTP | other *** search
/ Programming Sound Cards / Programming Sound Cards.iso / sound_56 / sbrec.asm < prev    next >
Assembly Source File  |  1995-01-01  |  5KB  |  147 lines

  1. ;==============================================================================
  2. ; Record and play in direct mode for SoundBlaster v1.00
  3. ;   André Baresel & Craig Jackson
  4. ;------------------------------------------------------------------------------
  5. ; Requirements: 8086, DOS 1.0, SoundBlaster (see BASEADDR)
  6. ; Supports    : Microphone, Line, CD
  7. ; Resolutions : 8-bit
  8. ;
  9.     .MODEL tiny
  10.     .8086
  11.  
  12.     BASEADDR           EQU 0220h       ;SoundBlaster base address
  13.     SAMPLEBUFFERLENGTH EQU 30000       ;count of samples in buffer
  14.  
  15. ;...
  16. ;   Arguments: DX = Status port
  17. ;   Returns  : n/a
  18. ;   Destroys : AL
  19. WAITWRITE   MACRO
  20.     LOCAL   loopWait
  21.  
  22. loopWait:
  23.     in      al,dx                       ;AL = ...
  24.     or      al,al                       ;...
  25.     js      loopWait                    ;   Jump: ...
  26. ENDM
  27.                                         ;samplerate (samples per second) = 1000000/pause
  28. ;...
  29. ;   Arguments: DX = Status port
  30. ;   Returns  : n/a
  31. ;   Destroys : AL
  32. WAITREAD    MACRO
  33.     LOCAL   loopWait
  34.  
  35. loopWait:
  36.     in      al,dx                       ;AL = ...
  37.     or      al,al                       ;...
  38.     jns     loopWait                    ;   Jump: ...
  39. ENDM
  40.  
  41.     .DATA
  42.     rectxt DB 13,10,'recording now ...','$'
  43.     plytxt DB 13,10,'playback now ...','$'
  44.  
  45.     .DATA?
  46.     SAMPLEBUFFER DB SAMPLEBUFFERLENGTH DUP (?)  ;Samplebuffer
  47.  
  48.     .CODE
  49.     .STARTUP
  50.  
  51.  
  52. loopMain:
  53.  
  54.     ; write an information to screen
  55.     mov     dx,offset rectxt
  56.     mov     ah,9
  57.     int     21h             ; text output
  58.     ; first record a bit
  59.     mov     cx,SAMPLEBUFFERLENGTH               ;CX = Video columns
  60.     mov     di,offset samplebuffer
  61. recordloop:
  62.     mov     dx,BASEADDR+00Ch            ;DX = DSP Write Data or Command
  63.     WAITWRITE                           ;
  64.     mov     al,020h                     ;AL = Direct ADC
  65.     out     dx,al                       ;   Output: DSP Write Data or Command
  66.  
  67.     add     dx,002h                     ;DX = DSP Data Available Status
  68. ;; -- I'm starting to use ADDs/SUBs so this stuff will work better if we
  69. ;;      decided to autodetect the BASEADDR -- also it generates shorter
  70. ;;      code (one byte of sign-extended immediate versus two bytes for MOV)
  71.     WAITREAD                            ;
  72.     sub     dx,004h                     ;DX = DSP Read Data
  73.     in      al,dx                       ;AL = ADC Data (high byte on SB16)
  74.     stosb                               ;Store sample in samplebuffer
  75.  
  76.     mov     ah,01                       ;AH = Check for character function
  77.     int     016h                        ;   Interrupt: Keyboard
  78.     loopz   recordloop                  ;   Loop: Continue sampling loop, until keypress
  79.     jnz     exit                        ;   Jump: if keypressed terminate program
  80.  
  81.     add     dx,002h                     ;DX = DSP Write Data or Command
  82.     mov     al,0D1h                     ;AL = Enable speaker
  83.     out     dx,al                       ;   Output: DSP Write Data or Command
  84.  
  85.     ; write an information to screen
  86.     mov     dx,offset plytxt
  87.     mov     ah,9
  88.     int     21h             ; text output
  89.     ; now playback samplebuffer
  90.     mov     si,offset samplebuffer
  91.     mov     cx,SAMPLEBUFFERLENGTH
  92. playbackloop:
  93.     mov     dx,BASEADDR+00Ch            ;DX = DSP Write Data or >Command<
  94.     WAITWRITE                           ;
  95.     mov     al,010h                     ;AL = Direct DAC
  96.     out     dx,al                       ;   Output: DSP Write Data or Command
  97.  
  98.     WAITWRITE                           ;
  99.     lodsb                               ;load next byte from buffer
  100.     out     dx,al                       ;AL = ADC Data (high byte on SB16)
  101.  
  102.     add     dx,002h                     ;DX = DSP Data Available Status
  103.     WAITWRITE                           ;
  104.  
  105.     mov     ah,01                       ;AH = Check for character function
  106.     int     016h                        ;   Interrupt: Keyboard
  107.     loopz   playbackloop                ;   Loop: ...
  108.  
  109.     mov     dx,BASEADDR+00Ch            ;DX = DSP Write Data or Command
  110.     mov     al,0D3h                     ;AL = Disable speaker
  111.     out     dx,al                       ;   Output: DSP Write Data or Command
  112.     jz      loopmain                    ;   Jump: ...
  113.  
  114. exit:
  115.     ; Terminate program
  116.     xor     ah,ah                       ;Read character, flush keypress
  117.     int     016h                        ;   Interrupt: Keyboard
  118.  
  119.     ret                                 ;Terminate program (old style - only with COM !!!)
  120.  
  121. ;;waitdspready:
  122. ;;        push      cx
  123. ;;        mov       dx,BASEADDR+00Ch
  124. ;;        mov       cx,100
  125. ;;@@litl: in        al,dx
  126. ;;        dec       cx
  127. ;;        jz        @@ende
  128. ;;        or        al,al
  129. ;;        js        @@litl
  130. ;;@@ende: pop       cx
  131. ;;        ret
  132. ;;  -- I nuked this in favor of in-line stuff because you don't actually do
  133. ;;          anything when CX=0 on return -- macros only 5 bytes each versus
  134. ;;          3 bytes for the 'CALL xxx' (not counting code inside of function)
  135.  
  136. ;;waitabit:
  137. ;;        push    cx
  138. ;;        mov     cx,pause
  139. ;;@o:     mov     ax,cx
  140. ;;        loop    @o
  141. ;;        pop     cx
  142. ;;        ret
  143. ;;  -- I think this is unnecessary if you query read/write status before
  144. ;;          doing anything
  145.  
  146.     END
  147.